﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.IO;
using System.IO.Tools;
using COFE.Core.Lister;
using COFE.Core;
using COFE.Core.Entry;

namespace COFE.IO.FSI
{
    public class EntryTypePropertyProvider : ISecondaryPropertyProvider<IFileSystemInfo>
    {
        #region Constructors

        public EntryTypePropertyProvider()
        {            
        }

        #endregion

        #region Methods

        public object[] GetSupportedProperty(IFileSystemInfo sourceObj)
        {
            if (sourceObj is IFileSystemInfo)
            {
                return new object[] {
                FileSystemInfoProperties.Type
                };
            }
            else return new object[] { };
        }

        public bool IsPropertyReadOnly(IFileSystemInfo sourceObj, object property)
        {
            return true;
        }

        public PropertyPair GetProperty(IFileSystemInfo sourceObj, object property)
        {
            if (sourceObj is IFileSystemInfo)
            {
                var sourceEntry = sourceObj as IFileSystemInfo;

                Func<IFileInfo, string> getProperty = (entry) =>
                {
                    return FileTypeInfoProvider.GetFileTypeInfo(COFEPath.GetExtension(entry.Name)).FileType;
                };

                if (property.Equals(FileSystemInfoProperties.Type))
                {
                    if (sourceEntry is IFileInfo)
                        return new PropertyPair(property, getProperty(sourceEntry as IFileInfo));

                    if (sourceEntry is IDirectoryInfo && (sourceEntry as IInternalDirectoryInfoExA).IsFileBasedFS)
                        return new PropertyPair(property, getProperty((sourceEntry as IInternalDirectoryInfoExA).FileBasedFSFile));

                    return new PropertyPair(property, "Folder");
                }

                throw new ArgumentException(property != null ? property.ToString() : "");
            }

            throw new NotSupportedException();
        }

        public void SetProperty(IFileSystemInfo sourceObj, object property, object value)
        {
            throw new NotImplementedException();
        }


        #endregion

        #region Data
  
        #endregion



        
    }
}
